<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <script>
            let arr = [1, 2, 3, 4, 5];
            // let arr1 = arr.slice(1, 3);
            // console.log(arr1); // [2, 3]
            // console.log(arr); // [1, 2, 3, 4, 5]
            // let arr2 = arr.slice();
            // console.log(arr2); //  [1, 2, 3, 4, 5]

            Array.prototype.mySlice = function (start = 0, end) {
                if (start < 0) start = start + this.length;
                if (end < 0) end = end + this.length;
                let newArr = [];
                for (; start < end; start++) {
                    newArr.push(this[start]);
                }
                return newArr;
            };
            let arr1 = arr.slice(1, 3);
            console.log(arr1); // [2, 3]
            console.log(arr); // [1, 2, 3, 4, 5]
            let arr2 = arr.slice();
            console.log(arr2);
            let arr3 = arr.slice(-2, -1);
            console.log(arr3);
        </script>
    </body>
</html>
